<template>
  <div class="app-container">
    <div class="query-container">
      <el-form
        ref="queryForm"
        :model="queryParams"
        :label-width="labelWidth"
        :inline="true"
      >
        <el-form-item :label="$t('serialNumber')" prop="serial_number">
          <el-input v-model="queryParams.serial_number" :placeholder="$t('inputserialNumber')" clearable size="small" @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item :label="$t('serialNumberName')" prop="serial_name">
          <el-input v-model="queryParams.serial_name" :placeholder="$t('inputserialNumberName')" clearable size="small" @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('search') }}</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('reset') }}</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="tool-container">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">{{ $t('addBtn') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <el-table-pro
      v-loading="loading"
      :highlight-current-row="true"
      :data="serialNumberList"
      :columns-config="columnsConfig"
      @sort="sortChange"
    >
      <el-table-column :label="$t('operate')" align="center" width="200" fixed="right" class-name="fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row)">{{ $t('detailBtn') }}</el-button>
          <el-button v-auth="[]" size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">{{ $t('modifyBtn') }}</el-button>
          <el-dropdown v-more size="mini" trigger="click" @command="command => handleCommand(command, scope.row)">
            <span class="el-dropdown-link">
              <i class="el-icon-d-arrow-right el-icon--right" />{{ $t('moreBtn') }}
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-auth="[]" command="handleDelete" icon="el-icon-delete">{{ $t('deleteBtn') }}</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table-pro>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.page_size"
      @pagination="getList"
    />
    <serialnumber-sheet ref="serialnumberSheet" @refreshList="getList" />
    <serialnumber-inquire ref="serialnumberInquire" />
  </div>
</template>

<script>
import { deleteSerialNumApi } from '../api/serialnumber.api'
import ElTablePro from '@/components/ElTablePro'
import listMixin from '@/mixins/ListMixin'
import { mapGetters } from 'vuex';
import serialnumberSheet from './serialnumber-sheet.vue';
import serialnumberInquire from './serialnumber-inquire.vue';
export default {
  name: 'SerialNumberList',
  components: {
    ElTablePro,
    serialnumberSheet,
    serialnumberInquire
  },
  mixins: [listMixin],
  data() {
    return {
      queryParams: {
        'serial_number': undefined,
        'serial_name': undefined
      },
      actionFuncName: 'master/getSerialNumberList',
      actionApi: {
        'delete': deleteSerialNumApi
      }
    }
  },
  computed: {
    ...mapGetters(['serialNumberList', 'name']),
    columnsConfig() {
      return [
        { prop: 'serial_number', label: this.$t('serialNumber'), 'width': 150 },
        { prop: 'serial_name', label: this.$t('serialNumberName'), 'width': 300 },
        { prop: 'created', label: this.$t('createdUser'), 'width': 100 },
        { prop: 'created_date', label: this.$t('createdDate'), 'width': 160 },
        { prop: 'created_program', label: this.$t('createdProgram'), 'width': 200, 'show-overflow-tooltip': true },
        { prop: 'updated', label: this.$t('updatedUser'), 'width': 100 },
        { prop: 'updated_date', label: this.$t('updatedDate'), 'width': 160 },
        { prop: 'updated_program', label: this.$t('updatedProgram'), 'width': 200, 'show-overflow-tooltip': true }
      ]
    },
    labelWidth() {
      // 根据国际化设置确定标签宽度,如果语言环境是英语，则返回150px
      return this.$i18n.locale === 'en' ? '150px' : '80px';
    }
  },
  methods: {
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case 'handleDelete':
          this.handleDelete(row);
          break;
        default:
          break;
      }
    },
    /** 点击明细按钮 */
    handleDetail(row) {
      this.$refs.serialnumberInquire.openSheetDialog(row);
    },
    handleAdd() {
      this.$refs.serialnumberSheet.openSheetDialog()
    },
    handleUpdate(row) {
      this.$refs.serialnumberSheet.openSheetDialog({ ...row })
    },
    handleDelete(row) {
      const confirmMessage = this.$t('dataDeleteConfirm', { title: this.$t('serialNumber'), value: row.serial_number })
      const successMessage = this.$t('deleteSuccess', { title: this.$t('serialNumber'), value: row.serial_number })
      this.handleAction('delete', row.id, confirmMessage, successMessage)
    }
  }

}
</script>

  <style scoped>
  </style>
